/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package design;

import code.AlbumPhotos;
import code.DownloadAlbum;
import code.FriendsList;
import com.restfb.Connection;
import com.restfb.FacebookClient;
import com.restfb.types.Album;
import com.restfb.types.FriendList;
import java.awt.Color;
import java.awt.Toolkit;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.JScrollPane;

/**
 *
 * @author Yuvraj Singh Babrah
 */
public class Skeleton extends javax.swing.JFrame {
    /* properties */
    private FacebookClient facebookClient = null;
    private Connection<FriendList> friendsList = null;
    private Connection<Album> albumsList = null;
    private String id = null;
    private String name = null;
    public static Map AlbumIdsForDownload = new LinkedHashMap();
    public static boolean[] AlbumsForDownload = new boolean[5];
    public static int index;
    public static JComboBox AlbumsList = null;
    public static JComboBox AlbumsId = null;
    public static JPanel AlbumsPicturePanel = null;
    public static JScrollPane AlbumsScrollPane = null;
    public static JPanel[] DownloadPanel = new JPanel[5];
    public static JLabel[] DownloadLabel = new JLabel[5];
    public static JProgressBar[] DownloadProgress = new JProgressBar[5];
    public static JLabel DownnloadStackLabel = null;
    public static JLabel Loader = null;
    public static String Location = null; 
    public static String Path = null;
    
    public Skeleton(){
        initComponents();
        design();
    }
        
    public Skeleton(FacebookClient facebookClient, String id, String name, Connection<FriendList> friendsList, Connection<Album> albumsList){
        this.facebookClient = facebookClient;
        this.id = id;
        this.name = name;
        this.friendsList = friendsList;
        this.albumsList = albumsList;
        initComponents(); // make frame
        design(); // little bit changes
        intelligence(); // initiate intelligence
    }
    
    public void design(){
        this.setTitle("hi " + name + " !!");
        this.setVisible(true);
        this.jLabel3.setVisible(false);
        this.jComboBox2.setVisible(false); // hide the ids box
        this.Loader = jLabel3;
        this.AlbumsList = jComboBox1;
        this.AlbumsId = jComboBox2;
        this.AlbumsPicturePanel = AlbumsPicturePane;
        this.AlbumsScrollPane = AlbumsScroll;
        this.setLocationRelativeTo(null);
        this.getContentPane().setBackground(new Color(59,89,152));
        try{
            this.setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/resources/icon_32.png")));
        }
        catch(Exception e){ }
        // tedious task but important
        DownloadPanel[0] = D1; DownloadPanel[1] = D2; DownloadPanel[2] = D3; DownloadPanel[3] = D4; DownloadPanel[4] = D5; // panels
        DownloadPanel[0].setVisible(false); DownloadPanel[1].setVisible(false); DownloadPanel[2].setVisible(false); DownloadPanel[3].setVisible(false); DownloadPanel[4].setVisible(false);
        DownloadLabel[0] = D1AlbumName; DownloadLabel[1] = D2AlbumName; DownloadLabel[2] = D3AlbumName; DownloadLabel[3] = D4AlbumName; DownloadLabel[4] = D5AlbumName; // labels
        DownloadProgress[0] = D1Progress; DownloadProgress[1] = D2Progress; DownloadProgress[2] = D3Progress; DownloadProgress[3] = D4Progress; DownloadProgress[4] = D5Progress; // progress bars
        this.DownnloadStackLabel = jLabel2;
        this.jLabel2.setVisible(true); 
    }
    
    public void intelligence(){
        // display friends
        new FriendsList(facebookClient, id, friendsList, FriendsScroll, FriendsPane).start();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jSeparator2 = new javax.swing.JSeparator();
        jSeparator3 = new javax.swing.JSeparator();
        jTabbedPane2 = new javax.swing.JTabbedPane();
        jScrollPane1 = new javax.swing.JScrollPane();
        FriendsScroll = new javax.swing.JScrollPane();
        FriendsPane = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        AlbumsScroll = new javax.swing.JScrollPane();
        AlbumsPane = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jComboBox1 = new javax.swing.JComboBox();
        jCheckBox1 = new javax.swing.JCheckBox();
        jButton1 = new javax.swing.JButton();
        jComboBox2 = new javax.swing.JComboBox();
        LoaderIcon = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        AlbumsPicturePane = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        DownloadsPane = new javax.swing.JPanel();
        D1 = new javax.swing.JPanel();
        D1AlbumName = new javax.swing.JLabel();
        D1Progress = new javax.swing.JProgressBar();
        D2 = new javax.swing.JPanel();
        D2AlbumName = new javax.swing.JLabel();
        D2Progress = new javax.swing.JProgressBar();
        D3 = new javax.swing.JPanel();
        D3AlbumName = new javax.swing.JLabel();
        D3Progress = new javax.swing.JProgressBar();
        D4 = new javax.swing.JPanel();
        D4AlbumName = new javax.swing.JLabel();
        D4Progress = new javax.swing.JProgressBar();
        D5 = new javax.swing.JPanel();
        D5AlbumName = new javax.swing.JLabel();
        D5Progress = new javax.swing.JProgressBar();
        jLabel2 = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenuItem6 = new javax.swing.JMenuItem();
        jSeparator4 = new javax.swing.JPopupMenu.Separator();
        jMenuItem3 = new javax.swing.JMenuItem();
        jMenu3 = new javax.swing.JMenu();
        jMenuItem4 = new javax.swing.JMenuItem();
        jSeparator5 = new javax.swing.JPopupMenu.Separator();
        jMenuItem5 = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem7 = new javax.swing.JMenuItem();
        jMenuItem8 = new javax.swing.JMenuItem();

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setResizable(false);

        jTabbedPane2.setFocusable(false);
        jTabbedPane2.setFont(new java.awt.Font("Calibri", 1, 13)); // NOI18N
        jTabbedPane2.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jTabbedPane2StateChanged(evt);
            }
        });

        jScrollPane1.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        jScrollPane1.setFocusable(false);

        FriendsScroll.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);

        FriendsPane.setBackground(new java.awt.Color(255, 255, 255));

        javax.swing.GroupLayout FriendsPaneLayout = new javax.swing.GroupLayout(FriendsPane);
        FriendsPane.setLayout(FriendsPaneLayout);
        FriendsPaneLayout.setHorizontalGroup(
            FriendsPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 836, Short.MAX_VALUE)
        );
        FriendsPaneLayout.setVerticalGroup(
            FriendsPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 479, Short.MAX_VALUE)
        );

        FriendsScroll.setViewportView(FriendsPane);

        jScrollPane1.setViewportView(FriendsScroll);

        jTabbedPane2.addTab("friends", jScrollPane1);

        jScrollPane2.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        jScrollPane2.setEnabled(false);
        jScrollPane2.setFocusable(false);
        jScrollPane2.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N

        AlbumsScroll.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);

        AlbumsPane.setBackground(new java.awt.Color(255, 255, 255));

        jPanel2.setBackground(new java.awt.Color(255, 255, 255));

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel1.setText("Select any album");

        jComboBox1.setMaximumRowCount(12);
        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "..." }));
        jComboBox1.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jComboBox1ItemStateChanged(evt);
            }
        });

        jCheckBox1.setBackground(new java.awt.Color(255, 255, 255));
        jCheckBox1.setText("High Quality");

        jButton1.setText("Download");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "test" }));

        jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/loader.GIF"))); // NOI18N
        jLabel3.setVisible(false);

        jButton2.setText("Clear Selection");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 263, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(10, 10, 10)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(LoaderIcon, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jCheckBox1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton2)
                .addGap(2, 2, 2)
                .addComponent(jButton1)
                .addGap(49, 49, 49))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel1)
                        .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jButton1)
                        .addComponent(jCheckBox1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(LoaderIcon)
                        .addComponent(jButton2)))
                .addGap(16, 16, 16))
        );

        javax.swing.GroupLayout AlbumsPicturePaneLayout = new javax.swing.GroupLayout(AlbumsPicturePane);
        AlbumsPicturePane.setLayout(AlbumsPicturePaneLayout);
        AlbumsPicturePaneLayout.setHorizontalGroup(
            AlbumsPicturePaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 845, Short.MAX_VALUE)
        );
        AlbumsPicturePaneLayout.setVerticalGroup(
            AlbumsPicturePaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 407, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout AlbumsPaneLayout = new javax.swing.GroupLayout(AlbumsPane);
        AlbumsPane.setLayout(AlbumsPaneLayout);
        AlbumsPaneLayout.setHorizontalGroup(
            AlbumsPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(AlbumsPaneLayout.createSequentialGroup()
                .addGap(245, 245, 245)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 341, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(259, Short.MAX_VALUE))
            .addComponent(AlbumsPicturePane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        AlbumsPaneLayout.setVerticalGroup(
            AlbumsPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(AlbumsPaneLayout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(AlbumsPicturePane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        AlbumsScroll.setViewportView(AlbumsPane);

        jScrollPane2.setViewportView(AlbumsScroll);

        jTabbedPane2.addTab("albums", jScrollPane2);

        jScrollPane3.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        jScrollPane3.setFocusable(false);

        DownloadsPane.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                DownloadsPaneMouseClicked(evt);
            }
        });
        DownloadsPane.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                DownloadsPaneFocusGained(evt);
            }
        });

        D1.setBackground(new java.awt.Color(255, 255, 255));
        D1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        D1.setAutoscrolls(true);

        D1AlbumName.setFont(new java.awt.Font("Segoe UI", 1, 12)); // NOI18N
        D1AlbumName.setText("New York City, New York");

        javax.swing.GroupLayout D1Layout = new javax.swing.GroupLayout(D1);
        D1.setLayout(D1Layout);
        D1Layout.setHorizontalGroup(
            D1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(D1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(D1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(D1Layout.createSequentialGroup()
                        .addComponent(D1AlbumName, javax.swing.GroupLayout.PREFERRED_SIZE, 684, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addComponent(D1Progress, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        D1Layout.setVerticalGroup(
            D1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(D1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(D1AlbumName, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(D1Progress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        D2.setBackground(new java.awt.Color(255, 255, 255));
        D2.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        D2AlbumName.setFont(new java.awt.Font("Segoe UI", 1, 12)); // NOI18N
        D2AlbumName.setText("New York City, New York");

        javax.swing.GroupLayout D2Layout = new javax.swing.GroupLayout(D2);
        D2.setLayout(D2Layout);
        D2Layout.setHorizontalGroup(
            D2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(D2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(D2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(D2Layout.createSequentialGroup()
                        .addComponent(D2AlbumName, javax.swing.GroupLayout.PREFERRED_SIZE, 684, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addComponent(D2Progress, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        D2Layout.setVerticalGroup(
            D2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(D2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(D2AlbumName, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(D2Progress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        D3.setBackground(new java.awt.Color(255, 255, 255));
        D3.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        D3AlbumName.setFont(new java.awt.Font("Segoe UI", 1, 12)); // NOI18N
        D3AlbumName.setText("New York City, New York");

        javax.swing.GroupLayout D3Layout = new javax.swing.GroupLayout(D3);
        D3.setLayout(D3Layout);
        D3Layout.setHorizontalGroup(
            D3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(D3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(D3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(D3Layout.createSequentialGroup()
                        .addComponent(D3AlbumName, javax.swing.GroupLayout.PREFERRED_SIZE, 684, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addComponent(D3Progress, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        D3Layout.setVerticalGroup(
            D3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(D3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(D3AlbumName, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(D3Progress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        D4.setBackground(new java.awt.Color(255, 255, 255));
        D4.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        D4AlbumName.setFont(new java.awt.Font("Segoe UI", 1, 12)); // NOI18N
        D4AlbumName.setText("New York City, New York");

        javax.swing.GroupLayout D4Layout = new javax.swing.GroupLayout(D4);
        D4.setLayout(D4Layout);
        D4Layout.setHorizontalGroup(
            D4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(D4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(D4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(D4Layout.createSequentialGroup()
                        .addComponent(D4AlbumName, javax.swing.GroupLayout.PREFERRED_SIZE, 684, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addComponent(D4Progress, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        D4Layout.setVerticalGroup(
            D4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(D4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(D4AlbumName, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(D4Progress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        D5.setBackground(new java.awt.Color(255, 255, 255));
        D5.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        D5AlbumName.setFont(new java.awt.Font("Segoe UI", 1, 12)); // NOI18N
        D5AlbumName.setText("New York City, New York");

        javax.swing.GroupLayout D5Layout = new javax.swing.GroupLayout(D5);
        D5.setLayout(D5Layout);
        D5Layout.setHorizontalGroup(
            D5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(D5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(D5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(D5Layout.createSequentialGroup()
                        .addComponent(D5AlbumName, javax.swing.GroupLayout.PREFERRED_SIZE, 684, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addComponent(D5Progress, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        D5Layout.setVerticalGroup(
            D5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(D5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(D5AlbumName, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(D5Progress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel2.setText("Download Stack Empty!! :(");
        jLabel2.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);

        javax.swing.GroupLayout DownloadsPaneLayout = new javax.swing.GroupLayout(DownloadsPane);
        DownloadsPane.setLayout(DownloadsPaneLayout);
        DownloadsPaneLayout.setHorizontalGroup(
            DownloadsPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(DownloadsPaneLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(DownloadsPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(D1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(DownloadsPaneLayout.createSequentialGroup()
                        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 797, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 9, Short.MAX_VALUE))
                    .addComponent(D2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(D3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(D4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(D5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        DownloadsPaneLayout.setVerticalGroup(
            DownloadsPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(DownloadsPaneLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(D1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(D2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(D3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(D4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(D5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jLabel2)
                .addContainerGap())
        );

        jScrollPane3.setViewportView(DownloadsPane);

        jTabbedPane2.addTab("downloads", jScrollPane3);

        jMenu1.setText("ease");

        jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_1, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem1.setText("my friends");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem1);

        jMenuItem2.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_2, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem2.setText("albums");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem2);

        jMenuItem6.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_3, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem6.setText("downloads");
        jMenuItem6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem6ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem6);
        jMenu1.add(jSeparator4);

        jMenuItem3.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F4, java.awt.event.InputEvent.ALT_MASK));
        jMenuItem3.setText("exit");
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem3);

        jMenuBar1.add(jMenu1);

        jMenu3.setText("downloads");

        jMenuItem4.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_J, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem4.setText("my downloads");
        jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem4ActionPerformed(evt);
            }
        });
        jMenu3.add(jMenuItem4);
        jMenu3.add(jSeparator5);

        jMenuItem5.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_J, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem5.setText("download folder");
        jMenuItem5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem5ActionPerformed(evt);
            }
        });
        jMenu3.add(jMenuItem5);

        jMenuBar1.add(jMenu3);

        jMenu2.setText("help");

        jMenuItem7.setText("about");
        jMenuItem7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem7ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem7);
        
        jMenuItem8.setText("clear downloads");
        jMenuItem8.addActionListener(new java.awt.event.ActionListener(){
            public void actionPerformed(java.awt.event.ActionEvent evt){
                jMenuItem8ActionPerformed(evt);
            }
        });
        jMenu3.add(jMenuItem8);

        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabbedPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 833, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabbedPane2)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jComboBox1ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jComboBox1ItemStateChanged
        // clear the selected photos list
        AlbumPhotos.SelectIds.clear();
        AlbumPhotos.SelectedButtons.clear();
        // select an album from the list
        if(evt.getStateChange() != 2)
            return;
        // load photos in the albums
        int index = ((JComboBox)evt.getSource()).getSelectedIndex();
        if(index < 0)
            return;
        else{
            String albumId = jComboBox2.getItemAt(index).toString();
            // clear the container
            AlbumsPicturePane.removeAll();
            AlbumsPicturePane.repaint();
            // show the loader
            jLabel3.setVisible(true);
            if(AlbumPhotos.flag == 0){
                AlbumPhotos.PhotoIds.clear(); // clear list
                new AlbumPhotos(facebookClient, albumId).start(); // thread
            }
        }
    }//GEN-LAST:event_jComboBox1ItemStateChanged

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // Download Album
        Boolean HighResolution = jCheckBox1.isSelected();
        String albumName = this.jComboBox1.getSelectedItem().toString();
        String albumId = AlbumPhotos.albumId; // album id
        long count = AlbumPhotos.count; // total photos in album
        // find the index
        for(int i = 0; i < 5; i ++){
            if(AlbumsForDownload[i] == false){
                index = i;
                break;
            }
            else if(i == 4){
                index = 5;
            }
        }
        if(index == 5){
            JOptionPane.showMessageDialog(null, "Unfortunately, you cannot download more than 5 albums at the same time.","Please wait!!", JOptionPane.ERROR_MESSAGE);
            return;
        }
        else if(AlbumIdsForDownload.containsKey(albumId)){
            JOptionPane.showMessageDialog(null, "This album is already up for download.","Download already under progree", JOptionPane.ERROR_MESSAGE);
            return;
        }
        if(AlbumPhotos.flag == 0){
            List PhotoIds = AlbumPhotos.PhotoIds;
            if(PhotoIds.size() == 0 || albumId == null){
                JOptionPane.showMessageDialog(null, "Either there is no album selected or the album doesn't have any pictures.","Hiccup!!", JOptionPane.ERROR_MESSAGE);
            }
            else{
                AlbumsForDownload[index] = true;
                DownloadPanel[index].setVisible(true);
                DownloadLabel[index].setText(jComboBox1.getSelectedItem().toString());
                if(AlbumPhotos.SelectIds.size() != 0){ // selected photos
                    new DownloadAlbum(facebookClient, index, albumId, albumName + " (Only Selected Photos)", HighResolution, AlbumPhotos.SelectIds).start(); // thread
                    DownloadProgress[index].setMaximum((int)AlbumPhotos.SelectIds.size());
                    DownloadProgress[index].setValue(0);
                    AlbumIdsForDownload.put(albumId, (int)AlbumPhotos.SelectIds.size());
                }
                else{ // complete album
                    DownloadProgress[index].setMaximum((int)PhotoIds.size());
                    DownloadProgress[index].setValue(0);
                    AlbumIdsForDownload.put(albumId, PhotoIds.size());
                    new DownloadAlbum(facebookClient, index, albumId, albumName, HighResolution, PhotoIds).start(); // thread
                }
                DownnloadStackLabel.setVisible(false);
                index ++;
            }
        }
        else{
            JOptionPane.showMessageDialog(null, "Loading of photos from the album is still under progress.","Please wait!!", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    public static synchronized void decrement(int index, String AlbumId){
        int count = Integer.parseInt(AlbumIdsForDownload.get(AlbumId).toString());
        count --;
        if(count == 0){
            AlbumIdsForDownload.remove(AlbumId);
            AlbumsForDownload[index] = false;
            DownloadPanel[index].setVisible(false);
            checkDownloadStack();
        }
        else{
            AlbumIdsForDownload.put(AlbumId, count);
            int getMax = DownloadProgress[index].getMaximum();
            int diff = getMax - count;
            DownloadProgress[index].setValue(diff);
        }
    }
    
    public static void checkDownloadStack(){
        int total = 0;
        for(int i = 0; i < 5; i ++){
            if(AlbumsForDownload[i] == false){                
                total ++;
            }
        }
        if(total == 5){
            DownnloadStackLabel.setVisible(true); 
        }
    }
    
    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        // show my friends pane
        jTabbedPane2.setSelectedIndex(0); 
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
        // show albums pane
        jTabbedPane2.setSelectedIndex(1); 
    }//GEN-LAST:event_jMenuItem2ActionPerformed

    private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem4ActionPerformed
        // show downloads
        jTabbedPane2.setSelectedIndex(2);
    }//GEN-LAST:event_jMenuItem4ActionPerformed

    private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
        // exit
        System.exit(0);
    }//GEN-LAST:event_jMenuItem3ActionPerformed

    private void DownloadsPaneFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_DownloadsPaneFocusGained
        // TODO add your handling code here:
    }//GEN-LAST:event_DownloadsPaneFocusGained

    private void DownloadsPaneMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_DownloadsPaneMouseClicked

    }//GEN-LAST:event_DownloadsPaneMouseClicked

    private void jTabbedPane2StateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jTabbedPane2StateChanged

    }//GEN-LAST:event_jTabbedPane2StateChanged

    private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem5ActionPerformed
        // open file chooser
        new FileChooser();
    }//GEN-LAST:event_jMenuItem5ActionPerformed

    private void jMenuItem6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem6ActionPerformed
        // open downloads
       jTabbedPane2.setSelectedIndex(2);
    }//GEN-LAST:event_jMenuItem6ActionPerformed

    private void jMenuItem7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem7ActionPerformed
        // About
        new About();
    }

    private void jMenuItem8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem8ActionPerformed
        // clear downloads stack
        for(int i = 0; i < 5; i ++){ // set false
            AlbumsForDownload[i] = false;
            DownloadPanel[i].setVisible(false);
        }
        DownnloadStackLabel.setVisible(true);
        AlbumIdsForDownload.clear();
    }
    //GEN-LAST:event_jMenuItem7ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // Clear the Selected Photos
        AlbumPhotos.SelectIds.clear();
        List Buttons = AlbumPhotos.SelectedButtons;
        Iterator Itr = Buttons.iterator();
        while(Itr.hasNext()){
            JButton Next = (JButton)Itr.next();
            int x = Next.getLocation().x;
            int y = Next.getLocation().y;
            Next.setSize(150, 150);
            Next.setLocation(x - 5, y - 5);
        }
        AlbumPhotos.SelectedButtons.clear();
    }//GEN-LAST:event_jButton2ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel AlbumsPane;
    private javax.swing.JPanel AlbumsPicturePane;
    private javax.swing.JScrollPane AlbumsScroll;
    private javax.swing.JPanel D1;
    private javax.swing.JLabel D1AlbumName;
    private javax.swing.JProgressBar D1Progress;
    private javax.swing.JPanel D2;
    private javax.swing.JLabel D2AlbumName;
    private javax.swing.JProgressBar D2Progress;
    private javax.swing.JPanel D3;
    private javax.swing.JLabel D3AlbumName;
    private javax.swing.JProgressBar D3Progress;
    private javax.swing.JPanel D4;
    private javax.swing.JLabel D4AlbumName;
    private javax.swing.JProgressBar D4Progress;
    private javax.swing.JPanel D5;
    private javax.swing.JLabel D5AlbumName;
    private javax.swing.JProgressBar D5Progress;
    private javax.swing.JPanel DownloadsPane;
    private javax.swing.JPanel FriendsPane;
    private javax.swing.JScrollPane FriendsScroll;
    private javax.swing.JLabel LoaderIcon;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JCheckBox jCheckBox1;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JComboBox jComboBox2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JMenuItem jMenuItem5;
    private javax.swing.JMenuItem jMenuItem6;
    private javax.swing.JMenuItem jMenuItem7;
    private javax.swing.JMenuItem jMenuItem8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JPopupMenu.Separator jSeparator4;
    private javax.swing.JPopupMenu.Separator jSeparator5;
    private javax.swing.JTabbedPane jTabbedPane2;
    // End of variables declaration//GEN-END:variables
}
